package com.zz.bsea.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zz.bsea.entity.User;
import com.zz.bsea.service.UserService;

/**
 * Servlet implementation class RegisterServlet
 */
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String uname=req.getParameter("name");
		 String upwd=req.getParameter("pwd");
		 UserService us=new UserService();
		 resp.setCharacterEncoding("utf-8");
		 resp.setContentType("text/html;charset=utf-8");
		 if(us.register(uname, upwd)) {
				//重定向
//				 resp.sendRedirect("/java11/BseaLogin.jsp");
				 //请求转发
				 req.getRequestDispatcher("/java11/BseaLogin.jsp").forward(req, resp);
			 }else {
				 resp.sendRedirect("/java11/BseaRegister.jsp");
			 }
		// resp.getWriter().append("注册结果："+us.register(uname, upwd));
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
